<template>
    <view class="uni-padding-wrap uni-common-pb">
        <form @submit="formSubmit" @reset="formReset">
            <view class="zk-logo">
                <image src="../../static/msg2.png"></image>
                <p>中凯准到</p>
            </view>
            <view class="uni-hello-text uni-common-pb">
                发祝福，上大屏，祝福写得越好越容易中大奖哦！
            </view>
            <view class="uni-textarea">
                <textarea name="bless" @input="bindTextAreaBlur" auto-height />
            </view>
            <view class="uni-btn-v">
                <button class="btn-submit" :disabled="isDisabled" formType="submit" type="primary">发送</button>
                <!-- <button type="primary" @tap="bindpostBless">发送</button> -->
            </view>
        </form>
    </view>
</template>
<script>
import {get,post} from '@/utils/index';
import {getActDetails,getSignList,postBless} from '@/utils/api';
//来自 graceUI 的表单验证， 使用说明见手册 http://grace.hcoder.net/doc/info/73-3.html
var  graceChecker = require("../../common/graceChecker.js");
export default {
    data(){
        return{
            text: '',
            isDisabled:true,
            postData:{
                message:'',
                act_id:0,
                avatarUrl:'',
                uid:0
            }
        }
    },
    onLoad:function(option){
        this.postData.act_id =option.id;
        let user = uni.getStorageSync('userInfo')
        this.postData.avatarUrl = user.avatarUrl
        this.postData.uid = user.Id
    },
    methods:{
        init(){
            
        },
        test(){
            console.log(this.postData)
        },
        bindTextAreaBlur: function (e) {
            // console.log(e.detail.value)
            this.postData.message = e.detail.value
            this.isDisabled = false
        },
        formSubmit: function (e) {
            // uni.showToast({ title: 'sdfsdfdsf', icon: "none" })
            //将下列代码加入到对应的检查位置
            //定义表单规则
            var rule = [
                {name:"bless", checkType : "string", checkRule:"5,100",  errorMsg:"限制输入5-100个字符"}
            ];
            //进行表单检查
            var formData = e.detail.value
            var checkRes = graceChecker.check(formData, rule)
            if(checkRes){
                this.bindpostBless()
                // uni.showToast({title:"验证通过!", icon:"none"})
            }else{
                uni.showToast({ title: graceChecker.error, icon: "none" })
            }
        },
        bindpostBless:function(){
            // console.log(this.postData)
            post(postBless,this.postData, true)
            .then((res)=>{
                uni.navigateTo({
                    url: '/pages/tabBar/act/actShow?id='+res.act_id
                });
                console.log(77,res)
                uni.showModal({
                    title: '提示',
                    content: '发送成功',
                    showCancel:false,
                    success: function (res) {
                        
                    }
                });
            })
        }
    }
}
</script>
<style>

</style>

